<h2>DESCRIPTION</h2> 

v.mapcalc performs overlay and buffer functions on vector map layers. New vector map layers can be created which are 
expressions of existing vector map layers, boolean vector operations and buffer functions. 

<h3>PROGRAM USE</h3> 
The module expects its input as expression in the following form: <br>
<br>
<b> result = expression </b>
<br>
<br>

This structure is similar to r.mapcalc, see <a href="r.mapcalc.html">r.mapcalc</a>. 
Where <b>result</b> is the name of a vector map layer that will contain the result of the calculation and 
<b>expression</b> is any valid combination of boolean and buffer operations for existing vector map layers. <br>

The input is given by using the first module option <i>expression=</i> . This option passes a <b>quoted</b> 
expression on the command line, for example: <br>
<div class="code"><pre>v.mapcalc expression="A = B"</pre></div> 
Where <b>A</b> is the new vector map layer that will be equal to the existing vector map layer <b>B</b> in this case. <br>
<div class="code"><pre>v.mapcalc "A = B"</pre></div> 
Will give the same result. 
<br>
<br>
<h3>OPERATORS AND FUNCTIONS</h3>

The module supports the following boolean vector operations: <br>
<div class="code"><pre>
 Boolean Name   Operator Meaning         Precedence   Correspondent function 
---------------------------------------------------------------------------------- 
 AND            &        Intersection          1      (v.overlay operator=and) 
 OR             |        Union                 1      (v.overlay operator=or)  
 DISJOINT OR    +        Disjoint union        1      (v.patch)              
 XOR            ^        Symmetric difference  1      (v.overlay operator=xor) 
 NOT            ~        Complement            1      (v.overlay operator=not) 

</pre></div>

And vector functions:
<div class="code"><pre>
 buff_p(A, size)    	  Buffer the points of vector map layer A with size
 buff_l(A, size)    	  Buffer the lines of vector map layer A with size
 buff_a(A, size)    	  Buffer the areas of vector map layer A with size
</pre></div>
<br>

<h2>NOTES</h2>
As shown in the operator table above, the boolean vector operators do not have different precedence. 
In default setting the expression will be left associatively evaluated. To define specific precedence use parentheses 
around these expressions, for example: <br>

<div class="code"><pre>
 v.mapcalc expression="D = A & B | C"
</pre></div>
Here the first intermediate result is the intersection of vector map layers <b>A & B</b>.  
This intermediate vector map layer is taken to create the union with vector map <b>C</b> to get the final result <b>D</b>.
It represents the default behaviour of left associativity. 

<div class="code"><pre>
 v.mapcalc expression="D = A & (B | C)"
</pre></div>
Here the first intermediate result is taken from the parenthesized union of vector map layers <b>B | C</b>.  
Afterwards the intersection of the intermediate vector map layer and <b>A</b> will be evaluated to get the final 
result vector map layer <b>D</b>.
<br>
<br>
It should be noticed, that the order in which the operations are performed does matter. 
Different order of operations can lead to a different result.

<h2>EXAMPLES</h2>
This example needed specific region setting. It should work in UTM and LL test locations. <br>
First set the regions extent and create two vector maps with one random points, respectively:
<div class="code"><pre>
g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3

v.random --o -z output=point_1 n=1 seed=1 
v.info point_1
v.random --o -z output=point_2 n=1 seed=2 
v.info point_2
</pre></div>

Then the vector algebra is used to create buffers around those points, cut out a subset and apply different boolean operation on the subsets in one statement:
<div class="code"><pre>
v.mapcalc --o expr="buff_and = (buff_p(point_1, 30.0) ~ buff_p(point_1, 20.0)) & \
                    (buff_p(point_2, 35) ~ buff_p(point_2, 25))"
v.mapcalc --o expr="buff_or  = (buff_p(point_1, 30.0) ~ buff_p(point_1, 20.0)) | \
                    (buff_p(point_2, 35) ~ buff_p(point_2, 25))"
v.mapcalc --o expr="buff_xor = (buff_p(point_1, 30.0) ~ buff_p(point_1, 20.0)) ^ \
                    (buff_p(point_2, 35) ~ buff_p(point_2, 25))"
v.mapcalc --o expr="buff_not = (buff_p(point_1, 30.0) ~ buff_p(point_1, 20.0)) ~ \
                    (buff_p(point_2, 35) ~ buff_p(point_2, 25))"
</pre></div>

<h2>REFERENCES</h2>

<tt><a href="http://www.dabeaz.com/ply/">PLY(Python-Lex-Yacc)</a></tt>

<h2>SEE ALSO</h2>

<em>
<a href="v.overlay.html">v.overlay</a>,
<a href="v.buffer.html">v.buffer</a>,
<a href="v.patch.html">v.patch</a>,
<a href="r.mapcalc.html">r.mapcalc</a>
</em>


<h2>AUTHOR</h2>

Thomas Leppelt, Soeren Gebbert, Thuenen Institut, Germany <br>

<p><i>Last changed: $Date: 2013-06-12 11:35:20 +0100 (Wed, 12 Jun 2013) $</i>

